<template>
	<div class="home">
		<view class="cu-custom" :style="{ height: wanlsys.height + 'px' }">
			<view class="cu-bar bg-bgcolor fixed" :style="{ height: wanlsys.height + 'px', paddingTop: wanlsys.top + 'px' }">
				<view class="action" @tap="$wanlshop.back(1)"><text class="wlIcon-fanhui1"></text></view>
				<view class="content" :style="{top: wanlsys.top + 'px'}">
					详情
				</view>
			</view>
		</view>
		
		<scroll-view class="scroll-view" scroll-y="true" id="main">
			<div class="detailT">
		
		        <view class="" v-if="data.video">
					<video :src="data.video" controls="true" style="width:100%;" :poster="$wanlshop.oss(data.images[0], 400, 0)" autoplay='true'></video>
				</view>
				<view class="" v-else>
						<swiper class="screen-swiper" :class="dotStyle?'square-dot':'round-dot'" :indicator-dots="true" :circular="true"
						 :autoplay="false" interval="5000" duration="500">
							<swiper-item v-for="(swiper, index) in data.images" :key="index">
								<image :src="$wanlshop.oss(swiper, 400, 0)" mode="aspectFill"></image>
							</swiper-item>
						</swiper>
				</view>
		
		
				<div class="details_title">
					<div class="details_title_name">
						{{data.title}}
					</div>
					
					<div class="details_title_text">
						<!-- <wanl-more :content="data.content"/> -->
						<rich-text :nodes="data.content"></rich-text>
					<!-- 	<u-parse :content="data.content"></u-parse> -->
					</div>
					<div class="details_title_time">
						<text @click="Tochat(data.users.id)" style="margin-right: 40upx;">{{data.users.nickname}}</text>  {{data.createtime_date}}
					</div>
					<div class="details_title_tip">
						<div class="details_title_tipl">
							<image src="../../../static/images/new/bq.png" mode=""></image>
						</div>
						<div class="details_title_tipr" v-for="(tag, index) in data.tags">
							{{tag}}
						</div>
					</div>
					<div class="details_titles">
						相关宝贝
					</div>
					<div class="details_list">
						<div class="details_list_item" v-if="data.goods.length>0" v-for="(goods, sub) in data.goods" :key="goods.id" @tap="onGoods(goods.id)">
							<div class="details_list_itemt">
								<image :src="$wanlshop.oss(goods.image, 50, 50)"></image>
							</div>
							<text>{{goods.title}}</text>
						</div>
					</div>
				</div>
			</div>
			<div class="detailB">
				<div class="detailB_title">共 {{data.comments}} 条评论</div>
<!-- 				<div class="detailB_input">
					<input type="text" disabled="true" placeholder="说点什么吧，万一火了呢~"  @tap="showModal('comments')" v-if="common.appConfig.comment_switch == 'Y'">
				</div> -->
				<div class="detailB_list" v-if="comments.length>0" v-for="(item,index) in comments" :key="index">
					<div class="detailB_list_t">
						<div class="detailB_list_tl" @click="Tochat(item.user.id)">
							<image :src="$wanlshop.oss(item.user.avatar, 35, 35, 2, 'avatar')" /></image>
						</div>
						<div class="detailB_list_tr">
							<text class="detailB_list_tlname" @click="Tochat(item.user.id)">{{item.user.nickname}}</text>
							<text class="detailB_list_tltime">{{$wanlshop.timeToDate(item.createtime)}}</text>
						</div>
					</div>
					<view class="detailB_list_b">
						<view class=""> {{item.content}}</view>
						<view class="flex detailB_list_b_cz">
							<view class="margin-right-sm margin-left-sm" @click="comment(item.id, item.user_id)">
								<image src="../../../static/images/new/ly.png" style="width: 40upx;height: 40upx;"></image>
							</view>
							<view class="margin-right-bj flex" @click="onCommentLike(item.id,item.islike)">
								<image src="../../../static/images/new/zan.png" style="width: 40upx;height: 40upx;" v-if="item.islike==0"></image> 
								<image src="../../../static/images/new/zan1.png" style="width: 40upx;height: 40upx;" v-if="item.islike==1"></image> 
								<view class="margin-left-xs" v-if="item.like>0">{{item.like}}</view>
							</view>
						</view>
					</view>
					<view class="detailB_list_1" v-if="item.child_list">
						<view class="margin-left-sm margin-bottom-xs" v-for="(item2, index2) in item.child_list" :key="index2">
							<text class="detailB_list_1_nc" @click="Tochat(item2.user.id)">用户{{item2.user.nickname}}</text>@ <text class="detailB_list_1_nc" @click="Tochat(item2.touser.id)">用户{{item2.touser.nickname}}: </text>
							<view class="">{{item2.content}}</view>
							<view class="flex detailB_list_b_cz2">
								<view class="margin-right-sm margin-left-sm" @click="comment(item.id, item2.user_id)">
									<image src="../../../static/images/new/ly.png" style="width: 30upx;height: 30upx;"></image>
								</view>
								<view class="margin-right-bj flex" @click="onCommentLike(item2.id,item2.islike)">
									<image src="../../../static/images/new/zan.png" style="width: 30upx;height: 30upx;" v-if="item2.islike==0"></image> 
									<image src="../../../static/images/new/zan1.png" style="width: 30upx;height: 30upx;" v-if="item2.islike==1"></image> 
									<view class="margin-left-xs" v-if="item2.like>0">{{item2.like}}</view>
								</view>
								<view class="margin-right-bj">{{$wanlshop.timeToDate(item2.createtime)}}</view>
							</view>
						</view>
					</view>
				</div>
			</div>
		</scroll-view>
		
		<view class="cu-bar search bg-white" style="position: fixed;bottom: 0;width: 100%;">
			<view class="search-form round" style="padding: 0 20upx;">
				<text class="cuIcon-edit"></text>
				<input disabled="true" :adjust-position="false" type="text" placeholder="说点什么" @tap="showModal('comments')" v-if="common.appConfig.comment_switch == 'Y'"></input>
			</view>
			<view class="action action_footer" v-if="data.isLike"  @tap="onLike()">
				<image src="../../../static/images/new/dz_selected.png" ></image>
				<text>{{data.like}}</text>
			</view>
			<view class="action action_footer" v-else  @tap="onLike()">
				<image src="../../../static/images/new/dz.png"></image>
				<text>{{data.like}}</text>
			</view>
			<view class="action action_footer" v-if="data.isFollow"  @tap="onFollow()">
				<image src="../../../static/images/new/sc_selected.png" ></image>
				<text>{{data.follows}}</text>
			</view>
			<view class="action action_footer" v-else  @tap="onFollow()">
				<image src="../../../static/images/new/sc.png"></image>
				<text>{{data.follows}}</text>
			</view>
			<view class="action action_footer" @tap="showModal('comments')" v-if="common.appConfig.comment_switch == 'Y'">
				<image src="../../../static/images/new/ly.png" ></image>
				<text>{{data.comments}}</text>
			</view>
		</view>
		
		
		<!--评论-->
		<view class="WANL-MODAL text-sm" @touchmove.stop.prevent="moveHandle">
			<view class="cu-modal bottom-modal" :class="modalName == 'comments' ? 'show' : ''" @tap="hideModal">
				<view class="cu-dialog" @tap.stop="">
					<view class="wanl-modal">
						<view class="foot flex justify-between align-center">
							<view class="input">
								<input type="text" placeholder="说点什么吧，万一火了呢~" v-model="newComments" name="input"></input>
							</view>
							
							<view class="text-xxl text-orange" @tap="addComment()">
								<text class="wlIcon-zhifeiji"></text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!--评论-->
		
	</div>
	
</template>

<script>
	import { mapState } from 'vuex';
	export default {
		computed: {
			...mapState(['user', 'common']),
		},
		data() {
			return {
				wanlsys: this.$wanlshop.wanlsys(),
				dotStyle: false,
				height: 0,
				find_id: 0,
				data: {
					shop: {
						avatar: '',
						shopname: '加载中...'
					}
				},
				comments: [],
				newComments: '',
				modalName: null,
				listData: [], //列表
				
				commentid:0.,
				touid:0,
				
			};
		},
		onLoad(option) {
			if(!option.id){
				option.id = 15;
			}
			this.find_id = option.id;
			this.loadData();
		},
		methods: {
			back(){
				uni.navigateBack();
			},
			async loadData(){
				this.$api.get({
					url: '/wanlshop/find/details',
					data: {
						id: this.find_id
					},
					success: res => {
						this.data = res;
						if(this.data['video']!=''){
							this.data['video']=this.$api.config.cdUrl+this.data['video'];
						}
						console.log(this.data);
						this.loadComments();
					}
				});
			},
			async loadComments(){
				this.$api.get({
					url: '/wanlshop/find/comments',
					data: {
						find_id: this.find_id,
						
					},
					success: res => {
						this.comments = res;
					}
				});
			},
			// 关注 & 取消关注
			onFollow() {
				var find = this.data;
				find.isFollow = !find.isFollow;
				if (find.isFollow) {
					find.follows += 1;
				} else {
					find.follows -= 1;
				}
				this.$api.post({
					url: '/wanlshop/find/setFollow',
					data: {
						id: find.id
					},
					success: res => {
						find.isFollow = res;
					}
				});
			},
			// 评论喜欢 & 取消喜欢
			onCommentLike(id,islike) {
				var comment_id = id;
				this.$api.post({
					url: '/wanlshop/find/setcommentsLike',
					data: {
						id: id
					},
					success: res => {
						this.loadComments();
					}
				});
			},
			// 喜欢 & 取消喜欢
			onLike() {
				var find = this.data;
				find.isLike = !find.isLike;
				if (find.isLike) {
					find.like += 1;
				} else {
					find.like -= 1;
				}
				this.$api.post({
					url: '/wanlshop/find/setLike',
					data: {
						id: find.id
					},
					success: res => {
						find.isLike = res;
					}
				});
			},
			// 弹出层
			async showModal(name) {
				var that = this;
				that.commentid = 0;
				that.touid = 0;
				this.modalName = name;
			},
			// 关闭弹出层
			hideModal() {
				this.modalName = null;
			},
			
			comment(commentid = 0, touid = 0) {
				var that = this;
				that.commentid = commentid;
				that.touid = touid;
				this.modalName = 'comments';
			},
			async addComment(){
				this.$api.post({
					url: '/wanlshop/find/addComments',
					data: {
						find_id: this.find_id,
						content: this.newComments,
						pid:this.commentid,
						to_user_id:this.touid,
					},
					success: res => {
						this.$wanlshop.msg('评论成功');
						this.data.comments += 1;
						this.loadComments();
					}
				});
				this.newComments = null;
				this.hideModal();
			},
			//留言
			Tochat(uid){
				if(this.user.id==uid){
					return false;
				}
				uni.navigateTo({
					url: '/pages/nutrition/chat?uid=' + uid
				});
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	
	.cu-modal.bottom-modal .cu-dialog{
		border-radius: 0;
	}
	.wanl-modal {
		padding-bottom: 125rpx !important;
		min-height: auto !important;
	}
	.wanl-modal .foot{
		bottom: 6px;
		text-align: left;
		padding: 0 25rpx;
		height: 100rpx !important;
		background-color: #f2f2f2;
	}
	.input{
		width: calc(100% - 70rpx);
	}
	.wanl-modal .foot input{
		background-color: #fff;
		height: 70rpx;
		padding: 0 25rpx;
		border-radius: 10rpx;
	}
	
	.action {
		.cuIcon-back {
			font-size: 35upx;
			color: #000000;
		}

		image {
			width: 41upx;
			height: 41upx;
		}
	}

	.screen-swiper {
		height: 1000upx;

		swiper-item {
			height: 100%;
			height: 100%;
		}

		// swiper-item{
		// 	height: 100%;
		// 	display: flex;
		// 	align-items: center;
		image {
			width: 100%;
			height: 100%;
		}

		// }
	}

	/deep/.uni-swiper-dots-horizontal {
		bottom: -30upx !important;
	}

	/deep/.uni-swiper-wrapper {
		overflow: inherit;
	}

	/deep/.uni-swiper-dot {
		width: 12upx;
		height: 12upx;
		background: #D8D8D8;
		border-radius: 50%;
	}

	/deep/.uni-swiper-dot-active {
		background: #FF6400;
		width: 12upx !important;
		height: 12upx !important;
	}

	/deep/.uni-swiper-dot-active::after {
		background: inherit !important;
	}

	.details_title {
		height: auto;
		overflow: hidden;
		margin-top: 69upx;
		padding: 0 30upx;

		.details_title_name {
			font-size: 36upx;
			font-weight: 400;
			color: #000000;
		}

		.details_title_text {
			margin-top: 33upx;
			height: auto;
			overflow: hidden;

			text {
				display: block;
				font-size: 24upx;
				font-weight: 400;
				color: #333333;
				margin-bottom: 10upx;
			}
		}

		.details_title_time {
			font-size: 20upx;
			font-weight: 400;
			color: #333333;
			margin-top: 31upx;
		}
	}

	.details_title_tip {
		height: 44upx;
		padding: 0 14upx;
		background: #F6F9FB;
		border-radius: 22upx;
		display: inline-flex;
		margin-top: 10upx;
		width: auto;
		align-items: center;
		justify-content: center;

		.details_title_tipl {
			width: 24upx;
			height: 24upx;
			background: #539BF4;
			border-radius: 50%;
			display: flex;
			align-items: center;
			justify-content: center;

			image {
				width: 16upx;
				height: 16upx;
			}
		}

		.details_title_tipr {
			font-size: 20upx;
			font-weight: 400;
			color: #3A8FF8;
			margin-left: 12upx;

		}
	}

	.details_titles {
		font-size: 26upx;
		font-weight: 400;
		color: #000000;
		margin: 32upx 0 23upx 0;
	}

	.details_list {
		height: auto;
		overflow: hidden;
		display: flex;
		flex-wrap: wrap;

		.details_list_item {
			width: 222upx;
			height: auto;
			overflow: hidden;
			margin-right: 12upx;

			.details_list_itemt {
				width: 222upx;
				height: 222upx;
				border-radius: 10upx;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			text {
				font-size: 20upx;
				font-weight: 400;
				color: #333333;
				padding: 20upx;
				display: block;
			}
		}

		.details_list_item:nth-child(3n) {
			margin-right: 0;
		}
	}

	.detailT {
		height: auto;
		overflow: hidden;
		background: #ffffff;
	}
	page,.home{
		height: 100%;
		overflow: hidden;
	}
	.scroll-view{
		height:calc(100% - 200upx);
		background: #F3F3F3;
	}
	.detailB{
		height: auto;
		overflow: hidden;
		margin-top: 14upx;
		background: #ffffff;
		padding:30upx 20upx 140upx ;
		.detailB_title{
			font-size: 24upx;
			font-weight: 400;
			color: #4F4F4F;
		}
		.detailB_input{
			width: 690upx;
			height: 64upx;
			background: #F3F3F3;
			border-radius: 32upx;
			margin-top: 30upx;
			input{
				padding: 0 30upx;
				width: 630upx;
				height: 100%;
				display: block;
				font-size: 24upx;
				font-weight: 400;
			}
		}
		.detailB_list{
			height: auto;
			overflow: hidden;
			padding:46upx 0 80upx 0;
			
			border-bottom: 1px solid #EEEEEE;
			.detailB_list_t{
				height: 60upx;
				display: flex;
				align-items: center;
				.detailB_list_tl{
					width: 60upx;
					height: 60upx;
					border-radius: 50%;
					overflow: hidden;
					image{
						width: 100%;
						height: 100%;
					}
				}
				.detailB_list_tr{
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					margin-left: 20upx;
					.detailB_list_tlname{
						font-size: 24upx;
						font-weight: 400;
						color: #2C2C2C;
					}
					.detailB_list_tltime{
						font-size: 20upx;
						font-weight: 400;
						color: #9E9E9E;
					}
				}
			}
			.detailB_list_b{
				width: 590upx;
				height: auto;
				overflow: hidden;
				font-size: 32upx;
				font-weight: 400;
				color: #2C2C2C;
				line-height: 48upx;
				margin-left: 80upx;
				margin-top: 20upx;
			}
			.detailB_list_b_cz{
				font-size: 28upx;
				flex-direction: row-reverse
			}
			.detailB_list_b_cz2{
				font-size: 24upx;
				flex-direction: row-reverse;
				line-height: 18px;
			}
			.detailB_list_1{
				width: 590upx;
				height: auto;
				overflow: hidden;
				font-size: 28upx;
				font-weight: 400;
				color: #2C2C2C;
				line-height: 48upx;
				margin-left: 80upx;
				margin-top: 20upx;
				background-color: #ECECEC;
			}
			.detailB_list_1_nc{
				color:#3A8FF8 ;
			}
		}
		
	}
	.action_footer{
		margin-right:24upx;
		image{
			width: 40upx;
			height: 40upx;
		}
		text{
			font-size: 26upx;
			font-weight: 400;
			color: #000000;
			margin-left: 10upx;
		}
	}
</style>
